import 'package:flutter/material.dart';
import '../custom/bottom_sheet.dart';
import 'package:wechat_camera_picker/wechat_camera_picker.dart';
import '/utils/permission.dart';

// 朋友圈 右上角 相机图标按钮
class CameraAction extends StatefulWidget {
  const CameraAction({super.key});

  @override
  State<CameraAction> createState() => _CameraActionState();
}

class _CameraActionState extends State<CameraAction> {

  Future<void> _pickFromCamera() async {
    /// 是否有相机权限
    bool hasPermissionCamera = await CheckPermission.camera();
    if(hasPermissionCamera) {
      // todo:优化 Don't use 'BuildContext's across async gaps.
      final AssetEntity? entity = await CameraPicker.pickFromCamera(context);
      if (entity != null) {
        debugPrint('我拍了￥${entity.toString()}');
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(right: 12),
      child: InkWell(
          onTap: () {
            final List<BottomSheetItem> mockData = [
              BottomSheetItem(
                child: const Column(
                  children: [
                    Text('拍摄'),
                    Text('照片或视频', style: TextStyle(color: Color(0xFFB6B6B6), fontSize: 10),),
                  ],
                ),
                onTap: _pickFromCamera
              ),
              BottomSheetItem(
                child: const Text('从相册选择'),
                onTap: () {
                  Navigator.pushNamed(context, 'EditArticlePage');
                  debugPrint('从相册选择');
                }
              ),
            ];

            showMyBottomSheet(context, mockData);
          },
          child: const Icon(Icons.camera_alt_outlined)
      ),
    );
  }
}
